<template>
    <div class="goodlist">
        <div class="top">
            <div class="span">网易严选</div>
            <div class="input">
                <uni-icons class="icon" type="search" size="20"></uni-icons>
                <div class="text">点击搜索更多</div>
            </div>
            <div class="btn">登录</div>
        </div>
        <div class="scroll">
            <scroll-view class="box" scroll-x enable-flex :scroll-with-animation="true">
                <div
                    :class="{ active: num == item.id }"
                    class="span"
                    @click="handler(item.id)"
                    v-for="(item, index) in scrollArr"
                    :key="index">
                    {{ item.name }}
                </div>
            </scroll-view>
            <div class="showdiv" v-show="show">
                <div class="max">
                    <div class="title">热门推荐</div>
                    <div class="typebox">
                        <div
                            @click="handler(item.id)"
                            :class="{ active: num == index }"
                            v-for="(item, index) in scrollArr"
                            :key="index"
                            class="type">
                            {{ item.name }}
                        </div>
                    </div>
                </div>
            </div>
            <uni-icons @click="show = !show" class="topicon" :type="show ? 'top' : 'bottom'" size="20"></uni-icons>
        </div>
        <scroll-view scroll-y enable-flex class="box" v-for="(item, index) in goodArr" :key="index">
            <div class="swiper" v-if="bannerArr.length">
                <swiper indicator-dots autoplay circular>
                    <swiper-item v-for="(item, index) in bannerArr" :key="index">
                        <image class="img" :src="item.picUrl" mode="widthFix" />
                    </swiper-item>
                </swiper>
            </div>
            <div class="center">
                <div class="first">{{ item.category.name }}</div>
                <div class="second">{{ item.category.frontName }}</div>
                <goods :list="item.itemList" />
            </div>
        </scroll-view>
    </div>
</template>

<script lang="ts" setup>
import { onLoad } from '@dcloudio/uni-app';
import { ref, onMounted } from 'vue';
import Ajax from '@/api/type';
const num = ref<any>(0);
const show = ref<boolean>(false);
const scrollArr = ref<any>([]);
const goodArr = ref<any>([]);
const bannerArr = ref<any>([]);
import TypeAjax from '@/api/type';
onMounted(() => {
    getType();
    getGoodList();
});
onLoad((options: any) => {
    // console.log(options);
    num.value = options.goodId;
});
const handler = (id: any) => {
    if (id == 11) {
        uni.reLaunch({
            url: '/pages/index/index',
        });
    } else
        uni.navigateTo({
            url: `/pages/goodlist/index?goodId=${id}`,
        });
};
const getType = async () => {
    let result: any = await TypeAjax.reqList();
    console.log(result);

    scrollArr.value = result.data.categoryL1List;
};
const getGoodList = async () => {
    let result: any = await Ajax.reqGoodList(num.value);
    console.log(result);
    goodArr.value = result.data.categoryItemList;
    bannerArr.value = result.data.currentCategory.bannerList;
};
</script>

<style scoped lang="less">
.goodlist {
    .top {
        display: flex;
        justify-content: space-between;
        height: 100rpx;
        margin: 10rpx 0;
        .span {
            font-weight: 900;
            margin: 0 auto;
        }
        .input {
            width: 450rpx;
            height: 60rpx;
            border-radius: 10rpx;
            line-height: 60rpx;
            background-color: lightgray;
            display: flex;
            align-items: center;

            .text {
                height: 30rpx;
                line-height: 30rpx;
                margin-left: 20rpx;
            }
            .icon {
                margin-left: 20rpx;
            }
        }
        .btn {
            width: 76rpx;
            border: 1px solid lightcoral;
            color: red;
            height: 40rpx;
            border-radius: 10rpx;
            line-height: 40rpx;
            margin: 0 auto;
            margin-top: 10rpx;
            text-align: center;
        }
    }
    .scroll {
        position: relative;
        margin-bottom: 10rpx;
        // overflow: hidden;
        .box {
            display: flex;
            overflow: hidden;
            height: 60rpx;
            width: 85%;
            .span {
                flex-shrink: 0;
                margin: 0 15rpx;
                padding: 10rpx;
                // width: 100rpx;
            }
            .active {
                border-bottom: 1px solid lightcoral;
                color: red;
            }
        }
        .showdiv {
            position: absolute;
            top: 0;
            left: 0;
            z-index: 99;
            background: rgba(116, 115, 117, 0.5);
            width: 100%;
            height: 100vh;
            .max {
                background: snow;
                .title {
                    color: #333;
                    font-size: 28rpx;
                    padding: 20rpx;
                }
                .typebox {
                    display: flex;
                    flex-wrap: wrap;
                    .type {
                        width: 100rpx;
                        color: #333;
                        font-size: 24rpx;
                        margin: 20rpx 10rpx;
                        padding: 15rpx;
                    }
                    .active {
                        border: 1px solid red;
                    }
                }
            }
        }
        .topicon {
            z-index: 100;
            position: absolute;
            right: 50rpx;
            top: 10rpx;
        }
    }
    .box {
        .swiper {
            .img {
                width: 100%;
                height: 400rpx;
            }
        }
        .center {
            margin: 20rpx 0;
            display: flex;
            justify-content: center;
            flex-direction: column;
            align-items: center;
            .first {
                color: #333;
                font-size: 32rpx;
            }
            .second {
                margin: 10rpx 0;
                color: #999;
                font-size: 24rpx;
            }
        }
    }
}
</style>
